package com.platform.qujia.pay.strategy;

import com.alibaba.fastjson.JSONObject;
import com.platform.qujia.pay.PayChannel;
import com.platform.qujia.pay.PaymentStrategy;
import com.platform.qujia.pay.QueryOrderStrategy;
import com.platform.qujia.pay.strategy.order.YunhuaQueryOrder;
import com.platform.qujia.pay.strategy.payment.YunhuaPayment;
import com.platform.qujia.utils.yunHua.VerifySignUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @date 2023/8/11
 */
@Component
public class YunhuaChannel implements PayChannel {

    public static final String SUCCESS_RETURN_VALUE = "{\"code\":\"0000\"}";

    //预下单接口
    public static final String API_PRE_ORDER = "/front/upi/preOrder";

    //手动支付
    public static final String API_MANUAL_PAY = "/front/upi/manualPay";

    //统一支付
    public static final String API_PAY = "/front/upi/pay";

    //支付结果查询
    public static final String API_QUERY = "/front/upi/query";

    //取消支付
    public static final String API_CANCEL = "/front/upi/cancel";


    //退款
    public static final String API_REFUND = "/front/upi/refund";

    //退款查询
    public static final String API_REFUND_QUERY = "/front/upi/refundQuery";

    public static final String RES_CODE_SUCCESS = "0000";

    public static final String DEFAULT_USER_ID = "100000000001";

    public static final String CHANNEL_ALI_SCAN="ali_scan";
    public static final String CHANNEL_WX_SCAN="wx_scan";




//	private YunHuaPayParam param;

    @Value("${yunhua.domainName}")
    private String domainName;
    @Autowired
    private YunhuaPayment yunhuaPayment;
    @Autowired
    private YunhuaQueryOrder queryOrder;

    public String getDomainName() {
        return domainName;
    }

    @Override
    public void init() {
        this.yunhuaPayment.setPayUrl(this.domainName+API_PAY);
        this.yunhuaPayment.setYunhuaChannel(this);
        this.queryOrder.setQueryOrderUrl(this.domainName+API_QUERY);
        this.queryOrder.setYunhuaChannel(this);
    }

    @Override
    public PaymentStrategy getPayStrategy() {
        return yunhuaPayment;
    }

    @Override
    public QueryOrderStrategy getQueryOrderStrategy() {
        return queryOrder;
    }

    public JSONObject signParam(JSONObject param,String secretKey){
        String sign= VerifySignUtil.getSign(param,secretKey);
        param.put("sign",sign);
        return param;
    }
}
